#ifndef __ET_CLIENT_H__
#define __ET_CLIENT_H__

#include "et_types.h"

#define DEBUG_PRINTF_EN				1

#define ET_MSG_LEN_MAX					128
#define ET_USER_ID_LEN_MAX				64
#define ET_TOPIC_LEN_MAX				32
#define ET_NET_IP_LEN_MAX				32
#define ET_NET_PORT_LEN_MAX			8
#define ET_FILE_ID_LEN_MAX				128

typedef struct {
	et_int32 crc32;
	et_long32 file_size;
	et_char source_ip_addr[ET_NET_IP_LEN_MAX];  //source storage ip address
	et_char port[ET_NET_PORT_LEN_MAX];
	et_char file_id[ET_FILE_ID_LEN_MAX];
} et_dfs_file_info_type;

typedef enum{
	EVENT_CLOUD_CONNECT = 1, //Connect cloud
	EVENT_CLOUD_DISCONNECT,//Disconnect cloud
	EVENT_LOGIN_KICK,	//You are kick to offline
	EVENT_CLOUD_SEND_FAILED,
	EVENT_CLOUD_SEND_SUCCESS,
	EVENT_LOCAL_SEND_FAILED,
	EVENT_LOCAL_SEND_SUCCESS,
	EVENT_LOCAL_CONNECT,
	EVENT_LOCAL_DISCONNECT
}et_event_no_type;

typedef struct{
	et_event_no_type event_no;
	et_int32 data;
}et_event_type;

typedef enum{
	SEND_TO_LOCAL = 1,
	SEND_TO_CLOUD,
	SEND_TO_ALL
}et_send_method_type;

typedef enum{
	ET_QOS0 = 0,
	ET_QOS1,
	ET_QOS2
}et_mes_qos_type;

typedef struct{
	et_char *server_addr;
	et_uint16 server_port;
	et_bool clr_offline_mes;
	et_bool auto_relogin;
	et_uint16 alive_sec;
}et_cloud_connect_type;

typedef enum{
	LIST_ONLINE = 1
}et_buddies_list_type;

typedef enum{
	MES_CHAT_TO_CHAT = 1,
	MES_FROM_GROUP_SUBTOPIC,
	MES_FROM_LOCAL,
	MES_FILE_TRANSFERS,
	MES_USER_ONLINE,
	MES_USER_OFFLINE,
	MES_USER_STATUS,
	MES_NOTICE_ADD_BUDDY,
	MES_NOTICE_REMOVE_BUDDY,
	MES_ONLINE_BUDDIES_LIST,
	MES_CHAT_TO_CHAT_EX
}et_mes_type;

typedef struct{
	et_uint16 mes_id;
	et_mes_qos_type mes_qos;
	et_char *payload;
	et_uint32 payload_len;
}et_context_mes_type;

typedef enum{
	ET_FILE_DOWN_TO_BUFF = 1,
	ET_FILE_DOWN_TO_FILE,
	ET_FILE_DOWN_TO_CALLBACK
}et_file_down_type;

typedef void * et_cloud_handle;
typedef void (*et_event_process_type)(et_event_type event);
typedef void (* et_msg_process_Type)(et_int32 type, et_char *send_userid, et_char *topic_name, et_int32 topic_len, et_context_mes_type *message);
typedef int (*et_file_down_process_type) (void *arg, const et_int64 file_size, const et_char *data, const et_int32 current_size);
typedef int (*et_file_uplaod_process_type) (void *arg, const et_int64 file_size, et_int32 sock);

et_char *et_sdk_var(void);
et_cloud_handle et_create_context(const et_char *userid, const et_char *app_key, const et_char *secret_key);
et_int32 et_destroy_context(et_cloud_handle *cloud_handle);
et_int32 et_set_callback(et_cloud_handle cloud_handle, et_msg_process_Type mes_call, et_event_process_type event_call);
et_int32 et_start_svr(et_cloud_handle cloud_handle);
et_int32 et_get_local_users(et_cloud_handle cloud_handle, et_char local_users_buf[][ET_USER_ID_LEN_MAX], et_uint32 users_num);
et_int32 et_login_cloud(et_cloud_handle cloud_handle, et_cloud_connect_type connect_para);
et_int32 et_relogin_cloud(et_cloud_handle cloud_handle, et_cloud_connect_type connect_para);
et_int32 et_get_buddies_online(et_cloud_handle cloud_handle);
et_int32 et_req_buddies_list(et_cloud_handle cloud_handle, et_buddies_list_type buddies_state);
et_int32 et_get_user_state(et_cloud_handle cloud_handle, et_char *userid);
et_int32 et_sub_user_state(et_cloud_handle cloud_handle, et_char *userid);
et_int32 et_unsub_user_state(et_cloud_handle cloud_handle, et_char *userid);
et_int32 et_sub_allbuddies_state(et_cloud_handle cloud_handle);
et_int32 et_unsub_allbuddies_state(et_cloud_handle cloud_handle);
et_int32 et_req_offline_msg(et_cloud_handle cloud_handle);
et_int32 et_chat_to(et_cloud_handle cloud_handle, et_uchar *data, et_int32 len, const et_char *userid, et_send_method_type send_method);
et_int32 et_publish_to_cloud(et_cloud_handle cloud_handle, et_uchar *data, et_int32 len, const et_char *topic, et_mes_qos_type qos);
et_int32 et_subscribe(et_cloud_handle cloud_handle, const et_char* topic, et_mes_qos_type qos);
et_int32 et_unsubscribe(et_cloud_handle cloud_handle, const et_char* topic);
et_int32 et_file_info(et_cloud_handle cloud_handle, et_char *file_str, et_dfs_file_info_type *file_info);
et_int32 et_down_file(et_cloud_handle cloud_handle,  et_dfs_file_info_type *file_info, et_file_down_process_type down_cb);
et_int32 et_logout_cloud(et_cloud_handle cloud_handle);
et_int32 et_stop_srv(et_cloud_handle cloud_handle);
#endif

